package com.itheima.controller.admin;

import com.itheima.DTO.SysUserDTO;
import com.itheima.DTO.SysUserPageDTO;
import com.itheima.VO.YddUserVO;
import com.itheima.json.PageBean;
import com.itheima.result.Result;
import com.itheima.service.SysUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys_user")
public class SysUserController {

    private final SysUserService sysUserService;

    @GetMapping("/list")
    public Result<PageBean<YddUserVO>> page(SysUserPageDTO sysUserPageDTO){
        PageBean<YddUserVO> userInfoVOPageBean = sysUserService.page(sysUserPageDTO);
        return Result.success(userInfoVOPageBean);
    }

    @PostMapping("/add")
    public Result<?> add(@RequestBody SysUserDTO sysUserDTO){
        sysUserService.insertSysUser(sysUserDTO);
        return Result.success();
    }

    @GetMapping("/rowInfo")
    public Result<?> rowInfo(String id){
        YddUserVO yddUserVO = sysUserService.selectUserById(id);
        return Result.success(yddUserVO);
    }

    @GetMapping("/del")
    public Result<?> delete(String id){
        sysUserService.deleteSysUserById(id);
        return Result.success();
    }

    @PostMapping("/update")
    public Result<?> update(SysUserDTO sysUserDTO){
        sysUserService.updateSysUser(sysUserDTO);
        return Result.success();
    }
}
